package com.guoxin.concurrentprogramming.chapter3.synccontrol;

import java.util.concurrent.locks.LockSupport;

public class LockSupportDemo {

    private static Object obj = new Object();

    private static class ChangeObjectThread extends Thread {
        public ChangeObjectThread(String name){
            super.setName(name);
        }

        @Override
        public void run() {
            synchronized (obj){
                System.out.println("in "+getName());
                LockSupport.park();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ChangeObjectThread t1 = new ChangeObjectThread("T1");
        ChangeObjectThread t2 = new ChangeObjectThread("T2");
        t1.start();
        Thread.sleep(100);
        t2.start();
        LockSupport.unpark(t1);
        LockSupport.unpark(t2);
        t1.join();
        t2.join();

    }

}
